
use "$working/full_ProdD_L6.dta", clear
gen lag = 6
forval i = 1/5 {
	append using "$working/full_ProdD_L`i'.dta"
	replace lag = `i' if missing(lag)
}
drop nic_08_2dig
sort lag
xpose, v clear

gen ord = 1 if _varname == "rho_hat"
replace ord = 1.5 if _varname == "rho_hat_se"
replace _varname =  "$\rho^1_D$" if _varname == "rho_hat" 
replace _varname = ""  if _varname == "rho_hat_se"
replace ord = 2 if _varname == "rho2_hat"
replace ord = 2.5 if _varname == "rho2_hat_se"
replace _varname =  "$\rho^2_D$" if _varname == "rho2_hat" 
replace _varname = ""  if _varname == "rho2_hat_se"
replace ord = 3 if _varname == "rho3_hat"
replace ord = 3.5 if _varname == "rho3_hat_se"
replace _varname =  "$\rho^3_D$" if _varname == "rho3_hat" 
replace _varname = ""  if _varname == "rho3_hat_se"
replace ord = 4 if _varname == "rho4_hat"
replace ord = 4.5 if _varname == "rho4_hat_se"
replace _varname =  "$\rho^4_D$" if _varname == "rho4_hat" 
replace _varname = ""  if _varname == "rho4_hat_se"
replace ord = 5 if _varname == "rho5_hat"
replace ord = 5.5 if _varname == "rho5_hat_se"
replace _varname =  "$\rho^5_D$" if _varname == "rho5_hat" 
replace _varname = ""  if _varname == "rho5_hat_se"
replace ord = 6 if _varname == "rho6_hat"
replace ord = 6.5 if _varname == "rho6_hat_se"
replace _varname =  "$\rho^6_D$" if _varname == "rho6_hat" 
replace _varname = ""  if _varname == "rho6_hat_se"
replace ord = 7 if _varname == "sigma_hat"
replace ord = 7.5 if _varname == "sigma_hat_se"
replace _varname =  "$\sigma$" if _varname == "sigma_hat" 
replace _varname = ""  if _varname == "sigma_hat_se"
replace ord = 8 if  _varname == "beta_lag_ln_IND"	
replace ord = 8.5 if  _varname == "beta_lag_ln_IND_se"	
replace _varname =  "$\ln\left(OutputComp^{CH}_{n(i),t-1}\right)$" if _varname == "beta_lag_ln_IND" 
replace _varname = "" if  _varname == "beta_lag_ln_IND_se"	
replace ord = 9 if  _varname == "beta_lag2_ln_IND"	
replace ord = 9.5 if  _varname == "beta_lag2_ln_IND_se"	
replace _varname =  "$\ln\left(OutputComp^{CH}_{n(i),t-2}\right)$" if _varname == "beta_lag2_ln_IND" 
replace _varname = "" if  _varname == "beta_lag2_ln_IND_se"	
replace ord = 10 if  _varname == "beta_lag3_ln_IND"	
replace ord = 10.5 if  _varname == "beta_lag3_ln_IND_se"	
replace _varname =  "$\ln\left(OutputComp^{CH}_{n(i),t-3}\right)$" if _varname == "beta_lag3_ln_IND" 
replace _varname = "" if  _varname == "beta_lag3_ln_IND_se"	
replace ord = 11 if  _varname == "beta_lag4_ln_IND"	
replace ord = 11.5 if  _varname == "beta_lag4_ln_IND_se"	
replace _varname =  "$\ln\left(OutputComp^{CH}_{n(i),t-4}\right)$" if _varname == "beta_lag4_ln_IND" 
replace _varname = "" if  _varname == "beta_lag4_ln_IND_se"	
replace ord = 12 if  _varname == "beta_lag5_ln_IND"	
replace ord = 12.5 if  _varname == "beta_lag5_ln_IND_se"	
replace _varname =  "$\ln\left(OutputComp^{CH}_{n(i),t-5}\right)$" if _varname == "beta_lag5_ln_IND" 
replace _varname = "" if  _varname == "beta_lag5_ln_IND_se"	
replace ord = 13 if  _varname == "beta_lag6_ln_IND"	
replace ord = 13.5 if  _varname == "beta_lag6_ln_IND_se"	
replace _varname =  "$\ln\left(OutputComp^{CH}_{n(i),t-6}\right)$" if _varname == "beta_lag6_ln_IND" 
replace _varname = "" if  _varname == "beta_lag6_ln_IND_se"	
replace ord = 14 if  _varname == "beta_lag_MA"	
replace ord = 14.5 if  _varname == "beta_lag_MA_se"	
replace _varname =  "$\ln\left(InputAccess^{CH}_{n(i),t-1}\right)$" if _varname == "beta_lag_MA" 
replace _varname = "" if  _varname == "beta_lag_MA_se"	
replace ord = 15 if  _varname == "beta_lag2_MA"	
replace ord = 15.5 if  _varname == "beta_lag2_MA_se"	
replace _varname =  "$\ln\left(InputAccess^{CH}_{n(i),t-2}\right)$" if _varname == "beta_lag2_MA" 
replace _varname = "" if  _varname == "beta_lag2_MA_se"	
replace ord = 16 if  _varname == "beta_lag3_MA"	
replace ord = 16.5 if  _varname == "beta_lag3_MA_se"	
replace _varname =  "$\ln\left(InputAccess^{CH}_{n(i),t-3}\right)$" if _varname == "beta_lag3_MA" 
replace _varname = "" if  _varname == "beta_lag3_MA_se"	
replace ord = 17 if  _varname == "beta_lag4_MA"	
replace ord = 17.5 if  _varname == "beta_lag4_MA_se"	
replace _varname =  "$\ln\left(InputAccess^{CH}_{n(i),t-4}\right)$" if _varname == "beta_lag4_MA" 
replace _varname = "" if  _varname == "beta_lag4_MA_se"	
replace ord = 18 if  _varname == "beta_lag5_MA"	
replace ord = 18.5 if  _varname == "beta_lag5_MA_se"	
replace _varname =  "$\ln\left(InputAccess^{CH}_{n(i),t-5}\right)$" if _varname == "beta_lag5_MA" 
replace _varname = "" if  _varname == "beta_lag5_MA_se"	
replace ord = 19 if  _varname == "beta_lag6_MA"	
replace ord = 19.5 if  _varname == "beta_lag6_MA_se"	
replace _varname =  "$\ln\left(InputAccess^{CH}_{n(i),t-6}\right)$" if _varname == "beta_lag6_MA" 
replace _varname = "" if  _varname == "beta_lag6_MA_se"	

replace ord = 20 if _varname == "perc_test"
replace ord = 20.5 if _varname == "se_perc_test"
replace _varname =  "Autocorrelation Test" if _varname == "perc_test" 
replace _varname = ""  if _varname == "se_perc_test"
replace ord = 21 if _varname == "Observations"
drop if missing(ord)

sort ord
forval i=1/6 {
	tostring v`i', force replace format(%12.3f)
	replace v`i' = "(" + v`i' + ")" if inlist(ord, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5, 19.5, 20.5)
	replace v`i' = "" if v`i' == "." | v`i' == "(.)"
}



la var _varname "Parameter"
texsave _varname v1 v2 v3 v4 v5 v6 using "$tables/demand_parameters.tex", ///
	footnote("Notes: Reports parameters for the Demand function based on GMM estimation of (\ref{eq: log demand DP}); see text for further details. Autocorrelation Test reports coefficient obtained by regressing residuals on lagged residuals. Standard errors, clustered by firm, in parentheses.") ///
	title("Demand paramters") ///
	nofix  replace location(h)  varlab marker(tab:demand_paramters) frag ///
	autonumber hlines(38) width(\textwidth)
